package com.hxci.zhangcong.controller;

import com.hxci.zhangcong.dao.TeacherDao;
import com.hxci.zhangcong.pojo.Teahcer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("tea")
public class TeacherController {
    @Autowired
    TeacherDao teacherDao;

    @RequestMapping("query")
    public String query(Model model){
        List<Teahcer> list = teacherDao.query();
        model.addAttribute("list",list);
        return "list";
    }

    @RequestMapping("add")
    public String add(){
        return "add";
    }

    @RequestMapping("save")
    public String save(Teahcer teahcer){
        if(teahcer.getId() ==null || teahcer.getId().equals("")){
            int a =teacherDao.save(teahcer);
        }else {
            int a =teacherDao.update(teahcer);
        }

        return "redirect: query";
    }
    @RequestMapping("del")
    public String del(Integer id){
        int a =teacherDao.del(id);
        return "redirect: query";
    }

    @RequestMapping("edit")
    public String edit(Model model ,Integer id){
        Teahcer tea =teacherDao.edit(id);
        model.addAttribute("tea",tea);
        return "add";
    }
    @RequestMapping("index")
    public String index(){
        return "index";
    }
}
